<?php
// php最大执行时间设置为：半个小时，php原来默认为30秒，爬不完
ini_set('max_execution_time', '0');
include '../vendor/autoload.php';// 使用composer安装后引入目录
include_once 'class/Mysql.php';
use QL\QueryList;

try {
//    $mysql = Mysql::getMysql();
//    $obj = $mysql->query("select * from source where status=0 ");
//    $result = $obj->fetchAll();
    $book_url='https://www.paopaokanshu.com/book/139272.html';
    $book_menu_url='https://www.paopaokanshu.com/Chapter/139272.html';
    $rules = array(
        'book_name' => array('#bookDetailWrapper h2', 'text'),    //获取纯文本格式的标题,并调用回调函数1
        'cover'=>array('#bookDetailWrapper .book-cover','src'),
        'author_name'=>array('#bookDetailWrapper .book-rand-a a','text'),
        'labels0'=>array('#bookDetailWrapper .BookTag a:eq(0)','text'),
        'labels1'=>array('#bookDetailWrapper .BookTag a:eq(1)','text'),
        'labels2'=>array('#bookDetailWrapper .BookTag a:eq(2)','text'),
        'labels3'=>array('#bookDetailWrapper .BookTag a:eq(3)','text'),
        'labels4'=>array('#bookDetailWrapper .BookTag a:eq(4)','text'),
        'book_status'=>array('#bookDetailWrapper p:eq(1)','text'),
        'describe'=>array('#bookSummary textarea','text'),
    );
    $data = QueryList::get($book_url)->rules($rules)->queryData();
    $total_pages =  QueryList::get($book_menu_url)->rules(['total_page' => array('output', 'text'),   ])->queryData();
    var_dump($total_pages);die;

}catch (Exception $e) {
    $exceptionlog = '文件 ['.$e->getFile().'] 第 '.$e->getLine().' 行出现未处理的异常'.PHP_EOL;
    $exceptionlog .= '代码:'.$e->getCode().PHP_EOL;
    $exceptionlog .= '信息:'.$e->getMessage().PHP_EOL;
    $exceptionlog .= '跟踪信息：'.$e->getTraceAsString();
    //记录错误
    error_log(date('Y-m-d H:i:s') . print_r($exceptionlog, 1) . PHP_EOL, 3, 'logs/'.date('Y-m-d').'_'.'exception.log');
}





?>